package xfuzzy.xfghl.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import xfuzzy.XmlParser;
import xfuzzy.util.XConstants;
import xfuzzy.util.XDialog;
import xfuzzy.util.XFileChooser;
import xfuzzy.util.XFileFilter;
import xfuzzy.xfedit.XfeditIcons;
import xfuzzy.xfghl.model.XfghlConfig;
import xfuzzy.xfghl.util.RandomNumberGenerator;
import xfuzzy.xfhl.model.spec.XfhlInputType;
import xfuzzy.xfhl.model.spec.XfhlOperSet;
import javax.swing.JComboBox;
import javax.swing.border.BevelBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

/**
 * Vista encargada de mostrar las opciones de configuracion de la herramienta Xfghl
 * 
 * @author Alberto David Fernandez Fernandez
 * 
 * */

@SuppressWarnings("serial")
public class XfghlConfigViewNew extends JFrame {

	/**
	 * Contenedor principal
	 * */
	private JPanel jContentPane;

	/**
	 * Contenedor del nombre del dataset y el numero de threads
	 * */
	private JPanel jPnlSystem;
	
	/**
	 * Nombre del sistema
	 * */
	private JTextField jTxtFldNameSystem;
	private JLabel jLabelName;
	
	/**
	 * Dataset
	 * */
	private JTextField jTxtFldDataSet;
	private JLabel jLblDataSet;
	
	/**
	 * Numero de hebras a utilizar
	 * */
	private JLabel jLblNumThread;
	private JTextField jTxtFldNumThread;
	
	/**
	 * Contenedor con los parametros del algoritmo
	 * */
	private JPanel jPnlAlgorithm;
	
	/**
	 * Contenedor de los parametros del algoritmo
	 * */
	private JPanel jPnlParam;
	
	/**
	 * Algoritmo RPROP
	 * */
	private JRadioButton jRBRprop;
	
	/**
	 * Algoritmo Mardquardt Levenberg
	 * */
	private JRadioButton jRBMarLev;
	
	/**
	 * ButtonGroup Algoritmo
	 * */
	private ButtonGroup jBGrAlg;
	
	/**
	 * Algoritmo seleccionado
	 * */
	private int AlgSelected;
	
	/**
	 * Parametro Initial Update
	 * */
	private JLabel jLblIniUpd;
	private JTextField jTxtFldUpd;
	
	/**
	 * Parametro Increase Factor
	 * */
	private JLabel jLblIncFact;
	private JTextField jTxtFldIncFactor;
	
	/**
	 * Parametro Decrease Factor
	 * */
	private JLabel jLblDecFact;
	private JTextField jTxtFldDecFactor;
	
	/**
	 * Contenedor con el limite de iteraciones
	 * */
	private JPanel jPnlEndCondition;
	
	/**
	 * Limite de iteraciones
	 * */
	private JLabel jLblLimitonIter;
	private JTextField jTxtFldLimitonIter;
	
	/**
	 * Contenedor de los Operadores
	 * */
	private JPanel jPnlOperSet;
	
	/**
	 * Contenedor del Operador AND
	 * */
	private JPanel jPnlOperAnd;
	
	/**
	 * ButtonGroup Operador AND
	 * */
	private ButtonGroup jBGrOperAnd;
	
	/**
	 * RadiobButton funcion Minimo
	 * */
	private JRadioButton jRBttnAndMin;
	
	/**
	 * RadioButton funcion Producto
	 * */
	private JRadioButton jRBttnAndProd;
	
	/**
	 * Contenedor del Operador de defuzificacion
	 * */
	private JPanel jPnlOperDefuz;
	
	/**
	 * RadioButton Funcion Weigthed Fuzzy Mean
	 * */
	private JRadioButton jRBttnDefWeig;
	
	/**
	 * ButtonGroup Operador de defuzificacion
	 * */
	private ButtonGroup jBGrOperDef;
	
	/**
	 * RadioButton Funcion Fuzzy Mean
	 * */
	private JRadioButton jRBttnDefFuzzyMean;
	
	/**
	 * Contenedor de estilo del tipo de entrada
	 * */
	private JPanel jPnlInType;
	
	/**
	 * Numero de funciones de entrada
	 * */
	private JLabel jLblNoMemberFuntion;
	private JTextField jTxtFldNoMemberFuntion;
	
	/**
	 * Boton de Free Triangles
	 * */
	private JButton jBtnFreeTri;
	
	/**
	 * Boton de Triangles Family
	 * */
	private JButton jBtnTriFam;
	
	/**
	 * Boton Free Shouldered Triangles
	 * */
	private JButton jBtnFreeShoulTri;
	
	/**
	 * Boton Shouldered-Triangular Family
	 * */
	private JButton jBtnShoulTriFam;
	
	/**
	 * Boton Free Gaussians
	 * */
	private JButton jBtnFreeGau;
	
	/**
	 * Boton B-Splines Family
	 * */
	private JButton jBtnB_SplinesFam;
	
	/**
	 * Objeto que contendra la configuacion de la herramienta
	 * */
	private XfghlConfig xfghlConfig;
	
	/**
	 * Para saber que boton del tipo de entrada esta activado
	 * */
	private JButton jBtnInTypeSelected;
	
	/**
	 * Tipo de entrada seleccionada
	 * */
	private int IN_TYPE;
	
	/**
	 * Operador AND seleccionado
	 * */
	private int operatorAND;
	
	/**
	 * Operador de defuzificacion seleccionado
	 * */
	private int defuzzOperator;
	
	/**
	 * Instancia de la ventana principal de la herramienta
	 * */
	private XfghlViewNew xfghlViewNew;
	
	/**
	 * Button Aceptar
	 * */
	private JButton jBtnAceptar;
	
	/**
	 * Button Cancelar
	 * */
	private JButton jBtnCancel;

	/**
	 * Panel con la configuracion del algoritmo genetico
	 * */
	private JPanel jPnlGenetic;
	
	/**
	 * Contenedor con las opciones generales del algoritmo genetico 
	 * */
	private JPanel panelGeneticOptions;

	/**
	 * Numero de individuos de la poblacion
	 * */
	private JLabel lblPopulationSize;
	private JTextField textFieldPopulationSize;
	
	/**
	 * Probabilidad de mutacion
	 * */
	private JLabel lblMutationProbability;
	private JTextField textFieldMutationProbability;
	
	/**
	 * Contenedor con las opciones de seleccion del algoritmo genetico
	 * */
	private JPanel panelSelectionOptions;
	
	/**
	 * Numero de individuos para la seleccion por torneo
	 * */
	private JLabel lblTournamentSize;
	private JTextField textFieldTournamentSize;

	/**
	 * Contenedor con las opciones de reemplazo del algoritmo genetico
	 * */
	private JPanel panelReplacementOptions;
	
	/**
	 * Factor de escala para el reemplazo crowding generalizado 
	 * */
	private JLabel lblScalingFactor;
	private JTextField textFieldScalingFactor;
	
	/**
	 * Contenedor con las opciones para la finalizacion del algoritmo genetico
	 * */
	private JPanel panelEndConditionOptions;

	/**
	 * Tipo de condicion de parada del algoritmo genetico
	 * */
	private JLabel lblTypecondition;
	private JComboBox comboBoxTypeCondition;
	
	/**
	 * Valor de la condicion de parada del algoritmo genetico
	 * */
	private JLabel lblValueEndCondition;
	private JTextField textFieldValueStopCondition;
	
	/**
	 * Salva la configuracion en un fichero XML
	 * */
	private JButton btnSave;
	
	/**
	 * Carga la configuracion desde un fichero XML
	 * */
	private JButton btnLoad;
	
	/**
	 * Constructor de la clase
	 * @param view Instancia de la ventana principal de la herramienta Xfghl
	 * */

	public XfghlConfigViewNew(XfghlViewNew view) {
		super();
		this.xfghlViewNew = view;
		this.xfghlConfig = null;
		initialize();
		inicializeForm();
	}
	
	/**
	 * Constructor de la clase
	 * @param view Instancia de la ventana principal de la herramienta Xfghl
	 * @param config Configuracion de la herramienta Xfghl
	 * */

	public XfghlConfigViewNew(XfghlViewNew view, XfghlConfig config) {

		super();
		initialize();
		this.xfghlViewNew = view;
		this.xfghlConfig = config;
		loadXfghlConfig();
	}
	/**
	 * Create the frame.
	 */
	public void initialize() {

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		setTitle("Xfghl Configuration");
		setSize(new Dimension(900, 490));
		setLocationRelativeTo(null);
		setResizable(false);
		setBackground(new Color(50, 50, 50));

		jContentPane = new JPanel();
		jContentPane.setLayout(null);
		// jpnlsystem
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
		gridBagConstraints.fill = GridBagConstraints.VERTICAL;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.weightx = 1.0;
		gridBagConstraints.gridx = 0;

		jPnlSystem = new JPanel();
		jPnlSystem.setLayout(null);
		jPnlSystem.setBounds(new Rectangle(22, 16, 250, 127));
		jPnlSystem.setBorder(BorderFactory.createTitledBorder(null, "System", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		jPnlSystem.setBackground(XConstants.jpanelColorBackground);

		jTxtFldNameSystem = new JTextField();
		jTxtFldNameSystem.setLocation(new Point(76, 36));
		jTxtFldNameSystem.setSize(new Dimension(150, 18));
		jTxtFldNameSystem.setBackground(XConstants.textbackground);
		jTxtFldNameSystem.setFont(XConstants.font);
		jTxtFldNameSystem.setEditable(false);
		jPnlSystem.add(jTxtFldNameSystem, gridBagConstraints);

		jLabelName = new JLabel();
		jLabelName.setBounds(new Rectangle(12, 36, 77, 18));
		jLabelName.setHorizontalAlignment(SwingConstants.LEFT);
		jLabelName.setForeground(Color.black);
		jLabelName.setFont(new Font("Dialog", Font.PLAIN, 10));
		jLabelName.setText("Name");
		jPnlSystem.add(jLabelName, null);

		jLblDataSet = new JLabel();
		jLblDataSet.setText("Data set");
		jLblDataSet.setSize(new Dimension(77, 18));
		jLblDataSet.setLocation(new Point(12, 63));
		jLblDataSet.setHorizontalAlignment(SwingConstants.LEFT);
		jLblDataSet.setForeground(Color.black);
		jLblDataSet.setFont(new Font("Dialog", Font.PLAIN, 10));
		jLblDataSet.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				selectDataSet();
			}
		});
		jPnlSystem.add(jLblDataSet, null);

		jTxtFldDataSet = new JTextField();
		jTxtFldDataSet.setSize(new Dimension(150, 18));
		jTxtFldDataSet.setBackground(XConstants.textbackground);
		jTxtFldDataSet.setLocation(new Point(76, 63));
		jTxtFldDataSet.setFont(XConstants.font);
		jTxtFldDataSet.setEditable(false);
		jTxtFldDataSet.addMouseListener(new java.awt.event.MouseAdapter() {
			public void mouseClicked(java.awt.event.MouseEvent e) {
				selectDataSet();
			}
		});
		jPnlSystem.add(jTxtFldDataSet, null);

		jLblNumThread = new JLabel();
		jLblNumThread.setBounds(new Rectangle(12, 93, 79, 18));
		jLblNumThread.setText("No. Threads");
		jLblNumThread.setHorizontalAlignment(SwingConstants.LEFT);
		jLblNumThread.setForeground(Color.black);
		jLblNumThread.setBorder(null);
		jLblNumThread.setFont(new Font("Dialog", Font.PLAIN, 10));
		jPnlSystem.add(jLblNumThread, null);

		jTxtFldNumThread = new JTextField();
		jTxtFldNumThread.setBounds(new Rectangle(76, 90, 150, 19));
		jTxtFldNumThread.setFont(XConstants.font);
		jTxtFldNumThread.setBackground(XConstants.textbackground);
		jPnlSystem.add(jTxtFldNumThread, null);
		jContentPane.add(jPnlSystem, null);

		// jpnlalgorithm
		jLblDecFact = new JLabel();
		jLblDecFact.setText("Decrease factor");
		jLblDecFact.setFont(new Font("Dialog", Font.PLAIN, 10));
		jLblDecFact.setBounds(new Rectangle(9, 67, 97, 16));

		jLblIncFact = new JLabel();
		jLblIncFact.setText("Increase factor");
		jLblIncFact.setFont(new Font("Dialog", Font.PLAIN, 10));
		jLblIncFact.setBounds(new Rectangle(9, 45, 98, 16));

		jLblIniUpd = new JLabel();
		jLblIniUpd.setText("Initial update");
		jLblIniUpd.setFont(new Font("Dialog", Font.PLAIN, 10));
		jLblIniUpd.setBounds(new Rectangle(9, 23, 98, 16));

		jPnlAlgorithm = new JPanel();
		jPnlAlgorithm.setLayout(null);
		jPnlAlgorithm.setBounds(new Rectangle(284, 16, 296, 230));
		jPnlAlgorithm.setBorder(BorderFactory.createTitledBorder(null, "Algorithm", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		jPnlAlgorithm.setBackground(XConstants.jpanelColorBackground);

		jPnlParam = new JPanel();
		jPnlParam.setLayout(null);
		jPnlParam.setBounds(new Rectangle(13, 48, 271, 101));
		jPnlParam.setBorder(BorderFactory.createTitledBorder(null, "Parameters", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		jPnlParam.setBackground(XConstants.jpanelColorBackground);

		jTxtFldUpd = new JTextField();
		jTxtFldUpd.setFont(XConstants.font);
		jTxtFldUpd.setBounds(new Rectangle(138, 22, 121, 18));
		jTxtFldUpd.setBackground(XConstants.textbackground);

		jPnlParam.add(jLblIniUpd, null);
		jPnlParam.add(jTxtFldUpd, null);
		jPnlParam.add(jLblIncFact, null);
		jPnlParam.add(jLblDecFact, null);

		jTxtFldIncFactor = new JTextField();
		jTxtFldIncFactor.setBounds(new Rectangle(138, 44, 121, 18));
		jTxtFldIncFactor.setFont(XConstants.font);
		jTxtFldIncFactor.setSize(new Dimension(121, 18));
		jTxtFldIncFactor.setBackground(XConstants.textbackground);
		jPnlParam.add(jTxtFldIncFactor, null);

		jTxtFldDecFactor = new JTextField();
		jTxtFldDecFactor.setBounds(new Rectangle(138, 66, 121, 18));
		jTxtFldDecFactor.setFont(XConstants.font);
		jTxtFldDecFactor.setBackground(XConstants.textbackground);
		jPnlParam.add(jTxtFldDecFactor, null);
		jPnlAlgorithm.add(jPnlParam, null);

		jLblLimitonIter = new JLabel();
		jLblLimitonIter.setBounds(new Rectangle(12, 22, 90, 16));
		jLblLimitonIter.setFont(new Font("Dialog", Font.PLAIN, 10));
		jLblLimitonIter.setText("No. Iterations");
		jPnlEndCondition = new JPanel();
		jPnlEndCondition.setLayout(null);
		jPnlEndCondition.setBounds(new Rectangle(13, 161, 270, 52));
		jPnlEndCondition.setBackground(XConstants.jpanelColorBackground);
		jPnlEndCondition.setBorder(BorderFactory.createTitledBorder(null, "End condition", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		jPnlEndCondition.add(jLblLimitonIter, null);

		jTxtFldLimitonIter = new JTextField();
		jTxtFldLimitonIter.setBounds(new Rectangle(137, 21, 121, 18));
		jTxtFldLimitonIter.setBackground(XConstants.textbackground);
		jTxtFldLimitonIter.setFont(XConstants.font);
		jTxtFldLimitonIter.setSize(new Dimension(121, 18));
		jPnlEndCondition.add(jTxtFldLimitonIter, null);
		jPnlAlgorithm.add(jPnlEndCondition, null);

		jRBRprop = new JRadioButton();
		jRBRprop.setHorizontalAlignment(SwingConstants.LEFT);
		jRBRprop.setBounds(new Rectangle(13, 19, 68, 21));
		jRBRprop.setText("RProp");
		jRBRprop.setFont(new Font("Dialog", Font.PLAIN, 10));
		jRBRprop.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				setAlgorithm(0);
			}
		});
		jPnlAlgorithm.add(jRBRprop, null);

		jRBMarLev = new JRadioButton();
		jRBMarLev.setBounds(new Rectangle(109, 19, 138, 21));
		jRBMarLev.setToolTipText("Mardquardt Levenberg");
		jRBMarLev.setHorizontalTextPosition(SwingConstants.LEFT);
		jRBMarLev.setText("Mardquardt Levenberg");
		jRBMarLev.setFont(new Font("Dialog", Font.PLAIN, 10));
		jRBMarLev.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				setAlgorithm(1);
			}
		});
		jPnlAlgorithm.add(jRBMarLev, null);
		jBGrAlg = new ButtonGroup();
		jBGrAlg.add(jRBRprop);
		jBGrAlg.add(jRBMarLev);
		jContentPane.add(jPnlAlgorithm, null);
		// jpnloperset

		jPnlOperSet = new JPanel();
		jPnlOperSet.setLayout(null);
		jPnlOperSet.setBounds(new Rectangle(284, 252, 295, 140));
		jPnlOperSet.setBorder(BorderFactory.createTitledBorder(null, "Operator Set", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		jPnlOperSet.setBackground(XConstants.jpanelColorBackground);

		jPnlOperDefuz = new JPanel();
		jPnlOperDefuz.setLayout(null);
		jPnlOperDefuz.setBounds(new Rectangle(15, 76, 268, 43));
		jPnlOperDefuz.setBorder(BorderFactory.createTitledBorder(null, "DEFUZ", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		jPnlOperDefuz.setBackground(XConstants.jpanelColorBackground);

		jRBttnDefFuzzyMean = new JRadioButton();
		jRBttnDefFuzzyMean.setBounds(new Rectangle(17, 12, 94, 24));
		jRBttnDefFuzzyMean.setText("FuzzyMean");
		jRBttnDefFuzzyMean.setFont(new Font("Dialog", Font.PLAIN, 10));
		jRBttnDefFuzzyMean.setBackground(XConstants.jpanelColorBackground);
		jRBttnDefFuzzyMean.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				defuzzOperator = XfhlOperSet.DefuzOperatorFuzzyMean;
			}
		});
		jPnlOperDefuz.add(jRBttnDefFuzzyMean, null);

		jRBttnDefWeig = new JRadioButton();
		jRBttnDefWeig.setBounds(new Rectangle(115, 13, 145, 22));
		jRBttnDefWeig.setFont(new Font("Dialog", Font.PLAIN, 10));
		jRBttnDefWeig.setText("WeigthedFuzzyMean");
		jRBttnDefWeig.setActionCommand("WeigthedFuzzyMean");
		jRBttnDefWeig.setHorizontalTextPosition(SwingConstants.LEADING);
		jRBttnDefWeig.setBackground(XConstants.jpanelColorBackground);
		jRBttnDefWeig.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				defuzzOperator = XfhlOperSet.DefuzOperatorWeightedFuzzyMean;
			}
		});
		jPnlOperDefuz.add(jRBttnDefWeig, null);
		jBGrOperDef = new ButtonGroup();
		jBGrOperDef.add(jRBttnDefFuzzyMean);
		jBGrOperDef.add(jRBttnDefWeig);
		jPnlOperSet.add(jPnlOperDefuz, null);

		jPnlOperAnd = new JPanel();
		jPnlOperAnd.setLayout(null);
		jPnlOperAnd.setBackground(XConstants.jpanelColorBackground);
		jPnlOperAnd.setBorder(BorderFactory.createTitledBorder(null, "AND", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		jPnlOperAnd.setFont(new Font("Dialog", Font.PLAIN, 12));
		jPnlOperAnd.setBounds(new Rectangle(15, 25, 268, 39));

		jRBttnAndMin = new JRadioButton();
		jRBttnAndMin.setHorizontalAlignment(SwingConstants.LEFT);
		jRBttnAndMin.setBounds(new Rectangle(33, 12, 54, 21));
		jRBttnAndMin.setText("Min");
		jRBttnAndMin.setFont(new Font("Dialog", Font.PLAIN, 10));
		jRBttnAndMin.setBackground(XConstants.jpanelColorBackground);
		jRBttnAndMin.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				operatorAND = XfhlOperSet.AndOperatorMin;
			}
		});
		jPnlOperAnd.add(jRBttnAndMin, null);

		jRBttnAndProd = new JRadioButton();
		jRBttnAndProd.setHorizontalAlignment(SwingConstants.LEFT);
		jRBttnAndProd.setBounds(new Rectangle(168, 10, 51, 24));
		jRBttnAndProd.setText("Prod");
		jRBttnAndProd.setFont(new Font("Dialog", Font.PLAIN, 10));
		jRBttnAndProd.setHorizontalTextPosition(SwingConstants.LEFT);
		jRBttnAndProd.setBackground(XConstants.jpanelColorBackground);
		jRBttnAndProd.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				operatorAND = XfhlOperSet.AndOperatorProd;
			}
		});
		jPnlOperAnd.add(jRBttnAndProd, null);
		jBGrOperAnd = new ButtonGroup();
		jBGrOperAnd.add(jRBttnAndMin);
		jBGrOperAnd.add(jRBttnAndProd);
		jPnlOperSet.add(jPnlOperAnd, null);
		jContentPane.add(jPnlOperSet, null);

		// jbtnaceptar
		jBtnAceptar = new JButton();
		jBtnAceptar.setBounds(new Rectangle(101, 425, 149, 23));
		jBtnAceptar.setFont(XConstants.font);
		jBtnAceptar.setText("OK");
		jBtnAceptar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				if (validateForm()) {
					xfghlConfig = createXfghlConfig();
					xfghlViewNew.setConfig(xfghlConfig);
					xfghlViewNew.setEnabled(true);
					dispose();
				}
			}
		});
		jContentPane.add(jBtnAceptar, null);

		// jbtncancel
		jBtnCancel = new JButton();
		jBtnCancel.setBounds(new Rectangle(284, 425, 149, 23));
		jBtnCancel.setFont(XConstants.font);
		jBtnCancel.setText("CANCEL");
		jBtnCancel.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				xfghlViewNew.setEnabled(true);
				dispose();
			}
		});
		jContentPane.add(jBtnCancel, null);

		// jpnlintype
		jLblNoMemberFuntion = new JLabel();
		jLblNoMemberFuntion.setBounds(new Rectangle(12, 30, 128, 17));
		jLblNoMemberFuntion.setText("No. Mem. Funtions");
		jLblNoMemberFuntion.setHorizontalAlignment(SwingConstants.LEFT);
		jLblNoMemberFuntion.setForeground(Color.black);
		jLblNoMemberFuntion.setFont(new Font("Dialog", Font.PLAIN, 10));
		jPnlInType = new JPanel();
		jPnlInType.setLayout(null);
		jPnlInType.setBounds(new Rectangle(23, 155, 249, 237));
		jPnlInType.setBorder(BorderFactory.createTitledBorder(null, "INPUT TYPE", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
		jPnlInType.setBackground(XConstants.jpanelColorBackground);
		jPnlInType.add(jLblNoMemberFuntion, null);

		jTxtFldNoMemberFuntion = new JTextField();
		jTxtFldNoMemberFuntion.setBounds(new Rectangle(158, 29, 71, 18));
		jTxtFldNoMemberFuntion.setFont(XConstants.font);
		jTxtFldNoMemberFuntion.setBackground(XConstants.textbackground);
		jPnlInType.add(jTxtFldNoMemberFuntion, null);

		jBtnFreeTri = new JButton();
		jBtnFreeTri.setBounds(new Rectangle(32, 70, 95, 46));
		jBtnFreeTri.setBackground(new Color(238, 238, 238));
		jBtnFreeTri.setIcon(XfeditIcons.type1);
		jBtnFreeTri.setHorizontalAlignment(SwingConstants.CENTER);
		jBtnFreeTri.setFont(XConstants.font);
		jBtnFreeTri.setFocusPainted(false);
		jBtnFreeTri.setHorizontalTextPosition(SwingConstants.CENTER);
		jBtnFreeTri.setToolTipText("Free Triangles");
		jBtnFreeTri.setContentAreaFilled(false);
		jBtnFreeTri.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				jBtnFreeTri.setBorder(BorderFactory.createLoweredBevelBorder());
				IN_TYPE = XfhlInputType.FREE_TRIANGLES;
				restartBorder(jBtnFreeTri);
				jBtnInTypeSelected = jBtnFreeTri;
			}
		});
		jPnlInType.add(jBtnFreeTri, null);

		jBtnTriFam = new JButton();
		jBtnTriFam.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		jBtnTriFam.setBounds(new Rectangle(127, 70, 95, 46));
		jBtnTriFam.setFont(XConstants.font);
		jBtnTriFam.setToolTipText("Triangles Family");
		jBtnTriFam.setContentAreaFilled(false);
		jBtnTriFam.setFocusPainted(false);
		jBtnTriFam.setHorizontalAlignment(SwingConstants.CENTER);
		jBtnTriFam.setHorizontalTextPosition(SwingConstants.CENTER);
		jBtnTriFam.setIcon(XfeditIcons.typeF1);
		jBtnTriFam.setBackground(new Color(238, 238, 238));
		jBtnTriFam.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				jBtnTriFam.setBorder(BorderFactory.createLoweredBevelBorder());
				IN_TYPE = XfhlInputType.TRIANGULAR_FAMILY;
				restartBorder(jBtnTriFam);
				jBtnInTypeSelected = jBtnTriFam;
			}
		});
		jPnlInType.add(jBtnTriFam, null);

		jBtnFreeShoulTri = new JButton();
		jBtnFreeShoulTri.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		jBtnFreeShoulTri.setBounds(new Rectangle(32, 116, 95, 46));
		jBtnFreeShoulTri.setFont(XConstants.font);
		jBtnFreeShoulTri.setToolTipText("Free Shouldered Triangles");
		jBtnFreeShoulTri.setContentAreaFilled(false);
		jBtnFreeShoulTri.setFocusPainted(false);
		jBtnFreeShoulTri.setHorizontalAlignment(SwingConstants.CENTER);
		jBtnFreeShoulTri.setHorizontalTextPosition(SwingConstants.CENTER);
		jBtnFreeShoulTri.setIcon(XfeditIcons.type2);
		jBtnFreeShoulTri.setBackground(new Color(238, 238, 238));
		jBtnFreeShoulTri.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				jBtnFreeShoulTri.setBorder(BorderFactory.createLoweredBevelBorder());
				IN_TYPE = XfhlInputType.FREE_SHOULDERED_TRIANGLES;
				restartBorder(jBtnFreeShoulTri);
				jBtnInTypeSelected = jBtnFreeShoulTri;
			}
		});
		jPnlInType.add(jBtnFreeShoulTri, null);

		jBtnShoulTriFam = new JButton();
		jBtnShoulTriFam.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		jBtnShoulTriFam.setBounds(new Rectangle(127, 116, 95, 46));
		jBtnShoulTriFam.setFont(XConstants.font);
		jBtnShoulTriFam.setToolTipText("Shouldered-Triangular Family");
		jBtnShoulTriFam.setContentAreaFilled(false);
		jBtnShoulTriFam.setFocusPainted(false);
		jBtnShoulTriFam.setHorizontalAlignment(SwingConstants.CENTER);
		jBtnShoulTriFam.setHorizontalTextPosition(SwingConstants.CENTER);
		jBtnShoulTriFam.setIcon(XfeditIcons.typeF3);
		jBtnShoulTriFam.setBackground(new Color(238, 238, 238));
		jBtnShoulTriFam.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				jBtnShoulTriFam.setBorder(BorderFactory.createLoweredBevelBorder());
				IN_TYPE = XfhlInputType.SHOULDERED_TRIANGLES_FAMILY;
				restartBorder(jBtnShoulTriFam);
				jBtnInTypeSelected = jBtnShoulTriFam;
			}
		});
		jPnlInType.add(jBtnShoulTriFam, null);

		jBtnFreeGau = new JButton();
		jBtnFreeGau.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		jBtnFreeGau.setBounds(new Rectangle(32, 162, 95, 46));
		jBtnFreeGau.setFont(XConstants.font);
		jBtnFreeGau.setToolTipText("Free Gaussians");
		jBtnFreeGau.setContentAreaFilled(false);
		jBtnFreeGau.setFocusPainted(false);
		jBtnFreeGau.setHorizontalAlignment(SwingConstants.CENTER);
		jBtnFreeGau.setHorizontalTextPosition(SwingConstants.CENTER);
		jBtnFreeGau.setIcon(XfeditIcons.type3);
		jBtnFreeGau.setBackground(new Color(238, 238, 238));
		jBtnFreeGau.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				jBtnFreeGau.setBorder(BorderFactory.createLoweredBevelBorder());
				IN_TYPE = XfhlInputType.FREE_GAUSSIANS;
				restartBorder(jBtnFreeGau);
				jBtnInTypeSelected = jBtnFreeGau;
			}
		});
		jPnlInType.add(jBtnFreeGau, null);

		jBtnB_SplinesFam = new JButton();
		jBtnB_SplinesFam.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null, null));
		jBtnB_SplinesFam.setBounds(new Rectangle(127, 162, 95, 46));
		jBtnB_SplinesFam.setFont(XConstants.font);
		jBtnB_SplinesFam.setToolTipText("B-Splines Family");
		jBtnB_SplinesFam.setContentAreaFilled(false);
		jBtnB_SplinesFam.setFocusPainted(false);
		jBtnB_SplinesFam.setHorizontalAlignment(SwingConstants.CENTER);
		jBtnB_SplinesFam.setHorizontalTextPosition(SwingConstants.CENTER);
		jBtnB_SplinesFam.setIcon(XfeditIcons.typeF2);
		jBtnB_SplinesFam.setBackground(new Color(238, 238, 238));
		jBtnB_SplinesFam.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent e) {
				jBtnB_SplinesFam.setBorder(BorderFactory.createLoweredBevelBorder());
				IN_TYPE = XfhlInputType.B_SPLINES_FAMILY;
				restartBorder(jBtnB_SplinesFam);
				jBtnInTypeSelected = jBtnB_SplinesFam;
			}
		});
		jPnlInType.add(jBtnB_SplinesFam, null);
		jContentPane.add(jPnlInType, null);
		setContentPane(jContentPane);

		jPnlGenetic = new JPanel();
		jPnlGenetic.setBounds(592, 16, 294, 376);
		jPnlGenetic.setBorder(BorderFactory.createTitledBorder(null, "Genetic Algorithm", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));

		jContentPane.add(jPnlGenetic);
		jPnlGenetic.setLayout(null);

		panelGeneticOptions = new JPanel();
		panelGeneticOptions.setBounds(12, 25, 270, 91);
		jPnlGenetic.add(panelGeneticOptions);
		panelGeneticOptions.setBorder(BorderFactory.createTitledBorder(null, "Options", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		panelGeneticOptions.setLayout(null);

		lblPopulationSize = new JLabel("Population size");
		lblPopulationSize.setBounds(12, 27, 100, 15);
		panelGeneticOptions.add(lblPopulationSize);
		lblPopulationSize.setFont(new Font("Dialog", Font.PLAIN, 10));

		textFieldPopulationSize = new JTextField();
		textFieldPopulationSize.setBounds(158, 25, 100, 18);
		panelGeneticOptions.add(textFieldPopulationSize);
		textFieldPopulationSize.setBackground(XConstants.textbackground);
		textFieldPopulationSize.setFont(XConstants.font);
		textFieldPopulationSize.setColumns(10);

		lblMutationProbability = new JLabel("Mutacion probability");
		lblMutationProbability.setBounds(12, 54, 129, 15);
		panelGeneticOptions.add(lblMutationProbability);
		lblMutationProbability.setFont(new Font("Dialog", Font.PLAIN, 10));

		textFieldMutationProbability = new JTextField();
		textFieldMutationProbability.setBounds(158, 55, 100, 18);
		panelGeneticOptions.add(textFieldMutationProbability);
		textFieldMutationProbability.setColumns(10);
		textFieldMutationProbability.setBackground(XConstants.textbackground);
		textFieldMutationProbability.setFont(XConstants.font);

		panelSelectionOptions = new JPanel();
		panelSelectionOptions.setBounds(12, 128, 270, 58);
		jPnlGenetic.add(panelSelectionOptions);
		panelSelectionOptions.setBorder(BorderFactory.createTitledBorder(null, "Selection", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		panelSelectionOptions.setLayout(null);

		lblTournamentSize = new JLabel("Tournament size");
		lblTournamentSize.setBounds(12, 28, 100, 15);
		panelSelectionOptions.add(lblTournamentSize);
		lblTournamentSize.setFont(new Font("Dialog", Font.PLAIN, 10));

		textFieldTournamentSize = new JTextField();
		textFieldTournamentSize.setBounds(158, 25, 100, 18);
		panelSelectionOptions.add(textFieldTournamentSize);
		textFieldTournamentSize.setColumns(10);
		textFieldTournamentSize.setBackground(XConstants.textbackground);
		textFieldTournamentSize.setFont(XConstants.font);

		panelReplacementOptions = new JPanel();
		panelReplacementOptions.setBounds(12, 198, 270, 58);
		panelReplacementOptions.setBorder(BorderFactory.createTitledBorder(null, "Replacement", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		jPnlGenetic.add(panelReplacementOptions);
		panelReplacementOptions.setLayout(null);

		lblScalingFactor = new JLabel("Scaling factor");
		lblScalingFactor.setBounds(12, 25, 97, 15);
		panelReplacementOptions.add(lblScalingFactor);
		lblScalingFactor.setFont(new Font("Dialog", Font.PLAIN, 10));

		textFieldScalingFactor = new JTextField();
		textFieldScalingFactor.setBounds(158, 23, 100, 18);
		panelReplacementOptions.add(textFieldScalingFactor);
		textFieldScalingFactor.setColumns(10);
		textFieldScalingFactor.setBackground(XConstants.textbackground);
		textFieldScalingFactor.setFont(XConstants.font);

		panelEndConditionOptions = new JPanel();
		panelEndConditionOptions.setBounds(12, 268, 270, 91);
		panelEndConditionOptions.setBorder(BorderFactory.createTitledBorder(null, "End condition", TitledBorder.CENTER,
				TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 11), new Color(51, 51, 51)));
		jPnlGenetic.add(panelEndConditionOptions);
		panelEndConditionOptions.setLayout(null);

		lblTypecondition = new JLabel("Type condition");
		lblTypecondition.setBounds(12, 25, 90, 15);
		lblTypecondition.setFont(new Font("Dialog", Font.PLAIN, 10));
		panelEndConditionOptions.add(lblTypecondition);

		comboBoxTypeCondition = new JComboBox();
		comboBoxTypeCondition.setBounds(119, 23, 140, 18);
		comboBoxTypeCondition.setBackground(XConstants.textbackground);
		comboBoxTypeCondition.setFont(XConstants.font);
		comboBoxTypeCondition.addItem("Generations");
		comboBoxTypeCondition.addItem("Evaluations");
		comboBoxTypeCondition.addItem("No improvements");
		comboBoxTypeCondition.setSelectedIndex(-1);
		panelEndConditionOptions.add(comboBoxTypeCondition);

		lblValueEndCondition = new JLabel("Value");
		lblValueEndCondition.setBounds(12, 52, 70, 15);
		lblValueEndCondition.setFont(new Font("Dialog", Font.PLAIN, 10));
		panelEndConditionOptions.add(lblValueEndCondition);

		textFieldValueStopCondition = new JTextField();
		textFieldValueStopCondition.setBounds(158, 50, 100, 18);
		panelEndConditionOptions.add(textFieldValueStopCondition);
		textFieldValueStopCondition.setBackground(XConstants.textbackground);
		textFieldValueStopCondition.setFont(XConstants.font);
		textFieldValueStopCondition.setColumns(10);

		btnSave = new JButton("Save");
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				if (validateForm()) {
					xfghlConfig = createXfghlConfig();

					if (xfghlConfig != null) {
						// Elegimos el nombre del fichero de datos
						XFileChooser fileDataSet = new XFileChooser(new File(""), XFileChooser.SAVE);
						fileDataSet.addFileFilter(new XFileFilter(".xml", "System Configuration File"));
						fileDataSet.showDialog();

						if (fileDataSet.getSelectedFile() != null) {
							String ruta = fileDataSet.getSelectedFile().getPath();
							if (!ruta.endsWith(".xml"))
								ruta += ".xml";
							File file = new File(ruta);

							String[] message = { "The configuration has been saved:", ruta };

							if (xfghlConfig.save(file))
								XDialog.showMessage(null, message);
							else
								XDialog.showMessage(null, "The configuration has NOT been saved.");
						}
					}
				} else {
					XDialog.showMessage(null, "Sorry, not exist any configuration.");
				}
			}
		});
		btnSave.setBounds(477, 423, 149, 25);
		jContentPane.add(btnSave);

		btnLoad = new JButton("Load");
		btnLoad.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {

				boolean exist = false;
				String ruta = "";
				do {
					XFileChooser fileDataSet = new XFileChooser(new File(""), XFileChooser.SELECT);
					fileDataSet.addFileFilter(new XFileFilter(".xml", "XML"));

					int sal = fileDataSet.showDialog();

					if (sal == XFileChooser.CANCELED) {
						exist = true;
					} else if (fileDataSet.getSelectedFile() != null) {
						File file = new File(fileDataSet.getSelectedFile().getPath());

						if (file.exists() && file.isFile()) {
							exist = true;
							ruta = fileDataSet.getSelectedFile().getPath();
						} else {
							XDialog.showMessage(null, "The xml file must exist.");
						}
					}
				} while (!exist);

				if (ruta.compareTo("") != 0) {
					XmlParser parse = new XmlParser();
					parse.parseXML(new File(ruta));
					XfghlConfig config = parse.getXfghlConfig();
					if (config != null) {
						xfghlConfig = config;
						// actualizar los campos!
						loadXfghlConfig();
					} else {
						XDialog.showMessage(null, "ERROR!! The xml configuration is incorrect.");
					}
				}
			}
		});
		btnLoad.setBounds(667, 423, 149, 25);
		jContentPane.add(btnLoad);

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				xfghlViewNew.setEnabled(true);
				dispose();
			}
		});
		this.inicializeForm();
	}

	/**
	 * Metodo que restaura el borde del boton anteriormente seleccionado
	 */
	private void restartBorder(JButton jbntSelect) {
		if (jBtnInTypeSelected != null && this.jBtnInTypeSelected != jbntSelect) {
			jBtnInTypeSelected.setBorder(BorderFactory.createRaisedBevelBorder());
		}
	}

	/**
	 * Genera la configuracion de la herramienta con los datos CORRECTOS introducidos
	 */
	private XfghlConfig createXfghlConfig() {

		String nameSystem = this.jTxtFldNameSystem.getText();
		int numIterAjus = Integer.parseInt(this.jTxtFldLimitonIter.getText());
		int numThread = Integer.parseInt(this.jTxtFldNumThread.getText());

		File file = new File(this.jTxtFldDataSet.getText());
		double iniUpd = Double.parseDouble(this.jTxtFldUpd.getText());
		double incFact = Double.parseDouble(this.jTxtFldIncFactor.getText());
		double decFact = Double.parseDouble(this.jTxtFldDecFactor.getText());
		int mfs = Integer.parseInt(this.jTxtFldNoMemberFuntion.getText());

		double mutProb = Double.valueOf(this.textFieldMutationProbability.getText());
		int popSize = Integer.valueOf(this.textFieldPopulationSize.getText());
		int tournamentSize = Integer.valueOf(this.textFieldTournamentSize.getText());
		double scaleFact = Double.valueOf(this.textFieldScalingFactor.getText());
		int stopSelec = -1;
		String selectedCondition = this.comboBoxTypeCondition.getSelectedItem().toString();
		if (selectedCondition.compareTo(XfghlProperties.stopConditionIterationsString) == 0)
			stopSelec = XfghlProperties.stopConditionIterationsValue;
		if (selectedCondition.compareTo(XfghlProperties.stopConditionEvaluationsString) == 0)
			stopSelec = XfghlProperties.stopConditionEvaluationsValue;
		if (selectedCondition.compareTo(XfghlProperties.stopConditionNoImprovementsString) == 0)
			stopSelec = XfghlProperties.stopConditionNoImprovementsValue;

		int valueStop = Integer.valueOf(this.textFieldValueStopCondition.getText());

		this.xfghlConfig = new XfghlConfig(nameSystem, numIterAjus, numThread, file, iniUpd, incFact, decFact, this.operatorAND,
				this.defuzzOperator, this.IN_TYPE, mfs, this.AlgSelected, mutProb, popSize, tournamentSize, scaleFact,
				stopSelec, valueStop);
		this.xfghlConfig.setLogFile("XfghlOutput.txt");
		this.xfghlConfig.setOutputBest("XfghlBest.xml");
		this.xfghlConfig.setCrossoverSeed(RandomNumberGenerator.generate());
		this.xfghlConfig.setMutationSeed(RandomNumberGenerator.generate());
		this.xfghlConfig.setPopopulationSeed(RandomNumberGenerator.generate());
		this.xfghlConfig.setReparationSeed(RandomNumberGenerator.generate());
		this.xfghlConfig.setSelectionSeed(RandomNumberGenerator.generate());
		this.xfghlConfig.setReplacementSeed(RandomNumberGenerator.generate());

		return this.xfghlConfig;
	}

	/**
	 * Metodo que comprueba que todos los campos sean correctos
	 * 
	 * @return True si el formulario es correcto, False en caso contrario
	 */
	private boolean validateForm() {

		String endLine = System.getProperty("line.separator");
		String message = "";
		boolean salida = true, isInteger = true, isDouble = true;
		int valueInteger = 0, popSize = 0;
		double valueDouble = 0.0;

		// Nombre del sistema
		if (this.jTxtFldNameSystem.getText().isEmpty()) {
			message += "The system name is required" + endLine;
		}

		// Ruta del archivo dataSet
		if (this.jTxtFldDataSet.getText().isEmpty()) {
			message += "The data set file is required." + endLine;
		}

		// Numero de hebras
		try {
			if (jTxtFldNumThread.getText().compareTo("default") != 0)
				valueInteger = Integer.parseInt(jTxtFldNumThread.getText());
			else
				valueInteger = 1;
		} catch (Exception e) {
			isInteger = false;
		}

		if (!isInteger || valueInteger <= 0) {
			message += "The threads number is required." + endLine;
		}

		isInteger = true;
		// Numero de funciones de pertenencia
		try {
			valueInteger = Integer.parseInt(jTxtFldNoMemberFuntion.getText());
		} catch (Exception e) {
			isInteger = false;
		}

		if (!isInteger || valueInteger <= 0) {
			message += "The No. Men. Funtions is required." + endLine;
		}

		// Tipo de funciones de entrada
		if (this.IN_TYPE == -1) {
			message += "The in type is required." + endLine;
		}

		/* ALGORITMO */

		// Eleccion del algoritmo
		if (this.AlgSelected == -1) {
			message += "No algorithm has been selected." + endLine;
		}

		// Initial update
		try {
			Double.parseDouble(jTxtFldUpd.getText());
		} catch (Exception e) {
			isDouble = false;
		}
		if (!isDouble) {
			message += "The paremeter 'Initial update' is required." + endLine;
		}
		// Increase factor
		isDouble = true;
		try {
			Double.parseDouble(jTxtFldIncFactor.getText());
		} catch (Exception e) {
			isDouble = false;
		}
		if (!isDouble) {
			message += "The paremeter 'Increase factor' is required." + endLine;
		}
		// Decrease factor
		isDouble = true;
		try {
			Double.parseDouble(jTxtFldDecFactor.getText());
		} catch (Exception e) {
			isDouble = false;
		}
		if (!isDouble) {
			message += "The paremeter 'Decrease factor' is required." + endLine;
		}

		// Numero de iteraciones
		isInteger = true;
		try {
			valueInteger = Integer.parseInt(jTxtFldLimitonIter.getText());
		} catch (Exception e) {
			isInteger = false;
		}

		if (!isInteger || valueInteger <= 0) {
			message += "The No. Iterations is required." + endLine;
		}
		// Operator AND
		if (jBGrOperAnd.getSelection() == null) {
			message += "The AND operator is required." + endLine;
		}
		// Operator DEFUZ
		if (jBGrOperDef.getSelection() == null) {
			message += "The DEFUZ operator is required." + endLine;
		}

		// ALGORITMO GENETICO
		isDouble = true;
		try {
			valueDouble = Double.parseDouble(this.textFieldMutationProbability.getText());
		} catch (Exception e) {
			isDouble = false;
		}

		if ((!isDouble) || (valueDouble < 0.0) || (valueDouble > 1.0))
			message += "The mutation probability is not valid." + endLine;

		isInteger = true;
		try {
			popSize = Integer.parseInt(this.textFieldPopulationSize.getText());
		} catch (Exception e) {
			isInteger = false;
		}

		if ((!isInteger) || (popSize <= 0) || (popSize < 30) || (popSize > 60))
			message += "The population size is not valid. Must be between 30 and 60." + endLine;

		isInteger = true;
		try {
			valueInteger = Integer.parseInt(this.textFieldTournamentSize.getText());
		} catch (Exception e) {
			isInteger = false;
		}

		if ((!isInteger) || (valueInteger <= 1) || (valueInteger > popSize))
			message += "The tournament size is not valid." + endLine;

		isDouble = true;
		try {
			valueDouble = Double.parseDouble(this.textFieldScalingFactor.getText());
		} catch (Exception e) {
			isDouble = false;
		}

		if ((!isDouble) || (valueDouble < 0.0))
			message += "The scaling factor is not valid." + endLine;

		if (this.comboBoxTypeCondition.getSelectedIndex() == -1)
			message += "The stop condition is not valid." + endLine;

		isInteger = true;
		try {
			valueInteger = Integer.parseInt(this.textFieldValueStopCondition.getText());
		} catch (Exception e) {
			isInteger = false;
		}

		if ((!isInteger) || (valueInteger < 0))
			message += "The stop condition value is not valid." + endLine;

		// if (message.compareTo("") != 0) {
		if (!message.isEmpty()) {
			salida = false;
			JOptionPane.showMessageDialog(this, message, "ERROR", JOptionPane.ERROR_MESSAGE);
		}
		return salida;
	}

	/**
	 * Metodo que inicializa el formulario con los valores por defecto
	 */
	public void inicializeForm() {

		// El nombre del sistema
		this.jTxtFldNameSystem.setText(this.xfghlViewNew.getOriginalSpec().getName());
		// Inicializamos el valor al numero de procesadores
		this.jTxtFldNumThread.setText("default");
		// Numero de funciones de pertencia
		this.jTxtFldNoMemberFuntion.setText(XfghlProperties.defaultNoMemberFuntion);
		// Estilo de entrada
		this.jBtnFreeTri.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		this.IN_TYPE = XfghlProperties.defaultInType;
		restartBorder(jBtnFreeTri);
		this.jBtnInTypeSelected = jBtnFreeTri;
		// Algoritmo
		this.setAlgorithm(XfghlProperties.defaultAlgorithm);
		this.jRBRprop.setSelected(true);
		this.jTxtFldLimitonIter.setText(String.valueOf(XfghlProperties.defaultlimitIterationNumber));
		// Operator set
		operatorAND = XfghlProperties.defaultAndOperator;
		jRBttnAndMin.setSelected(true);
		defuzzOperator = XfghlProperties.defaultDefuzzOperator;
		jRBttnDefFuzzyMean.setSelected(true);

		this.textFieldPopulationSize.setText(XfghlProperties.defaultPopulationSize);
		this.textFieldMutationProbability.setText(XfghlProperties.defaultMutationProbability);
		this.textFieldScalingFactor.setText(XfghlProperties.defaultScalingFactor);
		this.textFieldTournamentSize.setText(XfghlProperties.defaultTournamentSize);
		this.comboBoxTypeCondition.setSelectedIndex(XfghlProperties.defaultStopCondition);
		this.textFieldValueStopCondition.setText(XfghlProperties.defaultStopConditionValue);
	}

	/**
	 * Evento para seleccionar el dataSet
	 */
	private void selectDataSet() {

		boolean exist = false;
		do {
			XFileChooser fileDataSet = new XFileChooser(new File(""), XFileChooser.SELECT);
			fileDataSet.addFileFilter(new XFileFilter(".dat", "Data Set"));

			int sal = fileDataSet.showDialog();

			if (sal == XFileChooser.CANCELED) {
				exist = true;
			} else if (fileDataSet.getSelectedFile() != null) {
				File file = new File(fileDataSet.getSelectedFile().getPath());

				if (file.exists() && file.isFile()) {
					exist = true;
					jTxtFldDataSet.setText(fileDataSet.getSelectedFile().getPath());
				} else {
					XDialog.showMessage(null, "The data set file must exist.");
				}
			}
		} while (!exist);
	}

	/**
	 * Metodo que establece los parametros segun el algoritmo seleccionado
	 * @param i 0 para el algoritmo RProp, 1 para el algoritmo Marquardt Levenberg
	 */
	private void setAlgorithm(int i) {

		this.AlgSelected = i;
		String ini = "";
		String iniV = "";
		String incFacV = "";
		String decFacV = "";

		if (i == XfghlProperties.RProbAlgorithm) {
			ini = "Initial update";
			iniV = "0.1";
			incFacV = "1.5";
			decFacV = "0.7";
		} else {
			ini = "Ini. Hessian Addition";
			iniV = "1";
			incFacV = "10";
			decFacV = "0.1";
		}
		this.jLblIniUpd.setText(ini);
		this.jTxtFldUpd.setText(iniV);
		this.jTxtFldIncFactor.setText(incFacV);
		this.jTxtFldDecFactor.setText(decFacV);
	}
	
	/**
	 * Metodo que almacena los valores introducidos en los campos del formulario
	 * */
	
	public void loadXfghlConfig()  {
		
		this.jTxtFldNumThread.setText(String.valueOf(xfghlConfig.getNumThread()));

		this.jTxtFldNameSystem.setText(xfghlConfig.getNameSystem());
		this.jTxtFldLimitonIter.setText(String.valueOf(xfghlConfig.getnumIterAjust()));
		if (xfghlConfig.getValueThread() != -1)
			this.jTxtFldNumThread.setText(String.valueOf(xfghlConfig.getNumThread()));
		else
			this.jTxtFldNumThread.setText("default");

		this.AlgSelected = xfghlConfig.getAlgorithm();
		if (this.AlgSelected == 0)
			this.jRBRprop.setSelected(true);
		else
			this.jRBMarLev.setSelected(true);

		this.jTxtFldDataSet.setText(xfghlConfig.getDataSetFile().getAbsolutePath());
		this.jTxtFldUpd.setText(String.valueOf(xfghlConfig.getIniUpd()));
		this.jTxtFldIncFactor.setText(String.valueOf(xfghlConfig.getIncFact()));
		this.jTxtFldDecFactor.setText(String.valueOf(xfghlConfig.getDecFact()));
		this.jTxtFldNoMemberFuntion.setText(String.valueOf(xfghlConfig.getMfs()));

		this.operatorAND = xfghlConfig.getAndOperator();

		if (XfhlOperSet.AndOperatorMin == this.operatorAND)
			jRBttnAndMin.setSelected(true);
		else if (XfhlOperSet.AndOperatorProd == this.operatorAND)
			jRBttnAndProd.setSelected(true);

		this.defuzzOperator = xfghlConfig.getDefuzOperator();

		if (XfhlOperSet.DefuzOperatorFuzzyMean == this.defuzzOperator)
			jRBttnDefFuzzyMean.setSelected(true);
		else if (XfhlOperSet.DefuzOperatorWeightedFuzzyMean == this.defuzzOperator)
			jRBttnDefWeig.setSelected(true);

		this.IN_TYPE = xfghlConfig.getStileInput();

		switch (this.IN_TYPE) {
			case XfhlInputType.FREE_TRIANGLES:
				jBtnInTypeSelected = jBtnFreeTri;
				break;
			case XfhlInputType.FREE_SHOULDERED_TRIANGLES:
				jBtnInTypeSelected = jBtnFreeShoulTri;
				break;
			case XfhlInputType.FREE_GAUSSIANS:
				jBtnInTypeSelected = jBtnFreeGau;
				break;
			case XfhlInputType.TRIANGULAR_FAMILY:
				jBtnInTypeSelected = jBtnTriFam;
				break;
			case XfhlInputType.SHOULDERED_TRIANGLES_FAMILY:
				jBtnInTypeSelected = jBtnShoulTriFam;
				break;
			case XfhlInputType.B_SPLINES_FAMILY:
				jBtnInTypeSelected = jBtnB_SplinesFam;
				break;
			default:
				break;
		}
		jBtnInTypeSelected.setBorder(BorderFactory.createLoweredBevelBorder());

		// Parte algoritmo genetico
		this.textFieldPopulationSize.setText(String.valueOf(xfghlConfig.getPopulationSize()));
		this.textFieldMutationProbability.setText(String.valueOf(xfghlConfig.getMutationProbability()));
		this.textFieldScalingFactor.setText(String.valueOf(xfghlConfig.getScalingFactor()));
		this.textFieldTournamentSize.setText(String.valueOf(xfghlConfig.getTournamentSize()));
		this.textFieldValueStopCondition.setText(String.valueOf(xfghlConfig.getValueStopConditionGA()));
		if (xfghlConfig.getStopConditionGA() == XfghlProperties.stopConditionEvaluationsValue)
			this.comboBoxTypeCondition.setSelectedItem(XfghlProperties.stopConditionEvaluationsString);
		if (xfghlConfig.getStopConditionGA() == XfghlProperties.stopConditionIterationsValue)
			this.comboBoxTypeCondition.setSelectedItem(XfghlProperties.stopConditionIterationsString);
		if (xfghlConfig.getStopConditionGA() == XfghlProperties.stopConditionNoImprovementsValue)
			this.comboBoxTypeCondition.setSelectedItem(XfghlProperties.stopConditionNoImprovementsString);
	}
}
